16x62 USB Camera Robot Vision Interface Code

------------------------------------------------------------ 

by Rob Siemborski <rjs3+@andrew.cmu.edu>- 
low level libraries by Zhenlan Jin <zjin@andrew.cmu.edu>- 
tested by Brennan Sellner <bsellner@andrew.cmu.edu>- 
advisor Illah Nourbakhsh <illah@ri.cmu.edu>

-------------------------------------------------------------

This directory contains code to access the USB cameras via the
Java Media Framework (JMF). 
 This code was designed around JMF 2.1.1.

To begin, boot the computer and connect the camera to the USB port.

To use the code, you can examine the application "Driver.java" which
contains simple code to read from the camera and flash a rectangle on the screen image.  
It will also report the values of a pixel inside of the-rectangle, to show that you can access
the individual pixel values after grabbing an image.

To use this code in your own application, you will want to copy all of the 
class files in this directory to your own code.

In your application, start by getting an instance of the
UsbCamera class:

  UsbCamera cam = UsbCamera.getInstance()

This will initialize the camera.  

Note that there is only one camera object available in the entire JVM 
(getInstance will return references to the same object after the first is created).

To display a window with the camera's current view, simply use the setVisible method:

  cam.setVisible(true)

Every time you want to take a new picture, 
you can do so with the snap method (this will also update the picture on the screen):-

 cam.snap()--

You can do the "get picture" and "update screen" steps separately with:

  cam.getFrame();
  cam.draw();

Note that grabbing frames at close to the maximum frame rate will increase the lag between the time 
that you call getFrame and the time that that particular frame becomes available.  You probably don't 
ant to pull frames faster than 10 frames/second.

To read any pixel value off of the currently caputured
 image, use the getPixel method:	   

 /* Print out a random pixel */-	   
	 int pixel[] = cam.getPixel(30, 30);	    
	System.out.println(" r:"+pixel[UsbCamera.RED]+
			       " g:"+pixel[UsbCamera.GREEN]+
			       " b:"+pixel[UsbCamera.BLUE]);

Note the use of the UsbCamera.RED (BLUE, and GREEN) constants to access the array that is returned 
by the camera.  If an invalid pixel is requested, the function will return a null-reference.

You can also get 
"raw" pixel data (which is faster to do) by calling the getRawPixel method.  This will return a single integer 
that represents the red, blue, and green channels-all at once.  To separate them out, we provide some static 
methods:

int val = cam.getRawPixel(10,10)
int red = UsbCamera.getRed(val);
int blue = UsbCamera.getBlue(val);
int green = UsbCamera.getGreen(val);

You can get the size of the pixels from the UsbCamera.XSIZE and UsbCamera.YSIZE members.
To aid in debugging, you can draw a rectangle on top of the picture.  Do this using the setRect method:

	  cam.setRect(x, y, width, height)

The parameters are the x and y coordinates of the upper left-corner, followed by the width and height of the rectangle.

To remove the rectangle, do the following:
	  cam.unsetRect();

--Usage Notes:--------------------

This code offers no interface to adjust video parameters of the camera-such as brightness, contrast, 
auto gain, and auto whitebalance.  You will need to do that via other means.  If you are in the 16x62 
class, please see the "Using The Cameras" text file.

This code was specifically designed to work with 
the Logitech Quickcam Messenger cameras used by the 16x62 class.  It may need adjustment to use 
other USB cameras (specifically in terms of the image size).

To install the necessary parts of this softare on your system, please see the Install.txt file.